package db

import (
	"github.com/jinzhu/gorm"
	"time"
)

/**
TbAccount 帐号数据表
*/
type TbAccount struct {
	gorm.Model
	//Authority 权限
	Authority byte
	//Account 帐号
	Account string `gorm:"not null;unique;type:varchar(32)"`
	//Password 密码
	Password string `gorm:"not null;type:varchar(32)"`
	//IsUse 该帐号是否可用
	IsUse uint8 `gorm:"not null;type:smallint(1)"`
	//OldPassword 旧密码
	OldPassword string `gorm:"type:varchar(32)"`
	//Cash 现金
	Cash uint32
	//LastLoginTime 最后登陆时间
	LastLoginTime time.Time
	//Detail 帐号详细信息
	Detail TbAccountDetail
}

//TbAccountDetail 帐号详细信息
type TbAccountDetail struct {
	gorm.Model
	//Name 姓名
	Name string
	//Email 邮箱
	Email string
	//TbAccountID 帐号ID
	TbAccountID uint
}

func (self *TbAccount) BeforeCreate(scope *gorm.Scope) error {
	return scope.SetColumn("LastLoginTime", time.Now())
}
